﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LeftAndRightButton : MonoBehaviour {

	public ScrollRect scrollRect;
	public RectTransform content;
	private int starNum;
	private float everyMove;
	private float newPosition;

	// Use this for initialization
	void Start () {
		content = scrollRect.content;
		starNum = content.childCount;
		everyMove = (float) 1 / starNum;
	}
	
	// Update is called once per frame
	void Update () {
		scrollRect.horizontalNormalizedPosition = Mathf.Lerp(scrollRect.horizontalNormalizedPosition, newPosition, Time.deltaTime * 5f);
	}

	public void Left()
	{
		// scrollRect.horizontalNormalizedPosition = scrollRect.horizontalNormalizedPosition - everyMove;
		newPosition = scrollRect.horizontalNormalizedPosition - everyMove;
		// scrollRect.horizontalNormalizedPosition = Mathf.Lerp(scrollRect.horizontalNormalizedPosition, newPosition, Time.deltaTime * 5f);
	}

	public void Right()
	{
		// scrollRect.horizontalNormalizedPosition = scrollRect.horizontalNormalizedPosition + everyMove;
		newPosition = scrollRect.horizontalNormalizedPosition + everyMove;		
		// scrollRect.horizontalNormalizedPosition = Mathf.Lerp(scrollRect.horizontalNormalizedPosition, newPosition, Time.deltaTime * 5f);
		
	}
}
